package org.example.datastruct.hashmap;

import java.util.HashMap;
import java.util.Map;

/**
 * hashmap 是数组和链表(红黑树: 快速增删改查)
 * jdk8 hashmap扩容时做了哪些优化? 首先看扩容因子: 如果扩容因子小,则扩容的频率高,占用的空间大;如果扩容因子大,扩容频率低,hash冲突的几率变大
 * 导致需要更复杂的数据结构去避免hash冲突带来的影响
 *
 * hash冲突怎么解决: 当hash冲突时则需要在遍历判断
 *
 */
public class TestHashMap {

    public static void main(String[] args) {
        Map<String ,String> map = new HashMap<>();
        String key = "123";
        map.put(key,"00000");
        String s = map.get(key);
        /**
         * hash值如何对应hashmap里面的index呢?
         *
         */

        //System.out.println(key.hashCode());

        //System.out.println(Integer.toBinaryString(key.hashCode()));
        //return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
        System.out.println(key.hashCode());
        System.out.println(Integer.toBinaryString( key.hashCode()));
        System.out.println(Integer.toBinaryString( key.hashCode()>>>16));
        System.out.println(Integer.toBinaryString( key.hashCode() ^ (key.hashCode()>>>16)));
        System.out.println(Integer.toBinaryString( key.hashCode() ^ key.hashCode()>>>16));





        System.out.println(Integer.toBinaryString( -7));
        //带符号右移
        System.out.println(Integer.toBinaryString(-7>>1));
        //无符号右移
        System.out.println(Integer.toBinaryString(-7>>>1));
        System.out.println(-7>>1);



    }
}
